<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>产品详情</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 20px;
            background-color: #f8f9fa;
            color: #333;
        }

        .title-container {
            text-align: center;
            margin-bottom: 20px;
        }

        .container {
            display: flex;
            align-items: flex-start;
            background-color: white;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            gap: 20px;
        }

        .image-container {
            flex-basis: 300px;
            text-align: center;
            box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.1);
            border-radius: 10px;
            transition: transform 0.3s ease;
        }
        .product-img {
            max-width: 100%;
            display: block;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
        }

        .image-container:hover {
            transform: scale(1.1);
        }

        .details-container {
            flex-grow: 1;
            display: flex;
            flex-wrap: wrap;
        }

        .details-column {
            flex-basis: calc(50% - 20px);
            display: flex;
            flex-direction: column;
            gap: 10px;
        }

        .detail-title {
            width: 120px;
            white-space: nowrap;
            font-weight: bold;
        }

        .detail-input, .form-group select {
            display: inline-block;
            vertical-align: top;
            border: 1px solid #ccc;
            border-radius: 5px;
            padding: 5px;
            font-family: inherit;
            color: #333;
            background-color: #fff;
            /* 使输入框和下拉框宽度一致，并填充剩余空间 */
            width: calc(100% - 125px); /* 根据label的最小宽度加上间距调整 */
            margin-left: auto; /* 保持左对齐 */
            transition: border-color 0.3s ease-in-out;
        }

        .detail-title, .form-group label {
            display: inline-block;
            vertical-align: top;
            margin-right: 10px;
            font-weight: bold;
            /* 调整宽度以确保所有标题宽度一致，从而实现左对齐 */
            min-width: 80px; /* 可根据实际情况调整宽度 */
        }

        .actions-column {
            flex-basis: 100%;
            display: flex;
            justify-content: flex-end;
            gap: 10px;
            margin-top: 20px;
        }

        .btn {
            text-decoration: none;
            color: white;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            transition: opacity 0.3s ease, background-color 0.3s ease;
            border: none;
            outline: none;
            font-weight: bold;
        }

        .btn-primary {
            background-color: #007bff;
        }

        .btn-primary:hover, .btn-danger:hover {
            opacity: 0.8;
        }

        .btn-danger {
            background-color: #dc3545;
        }

        .modal {
            display: none;
            position: fixed;
            z-index: 1;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            overflow: auto;
            background-color: rgba(0, 0, 0, 0.9);
            transition: opacity 0.5s ease;
        }

        .modal-content {
            margin: 5% auto;
            display: block;
            width: 80%;
            max-width: 700px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
            border-radius: 5px;
            animation: modalOpen 0.5s ease;
        }

        @keyframes modalOpen {
            from {transform: translateY(-50px); opacity: 0;}
            to {transform: translateY(0); opacity: 1;}
        }

        .close {
            position: absolute;
            top: 15px;
            right: 35px;
            color: #f1f1f1;
            font-size: 40px;
            font-weight: bold;
            cursor: pointer;
        }

        .form-group {
            display: flex;
            align-items: center;
            margin-bottom: 10px;
            /* 确保容器填满其父元素，以便内部元素正确对齐 */
            width: 100%;
        }

        .form-group label {
            font-weight: bold;
            margin-right: 10px;
            white-space: nowrap;
        }

        /* 统一选择器和输入框的外观 */
        .form-group select:hover, .detail-input:hover, .detail-input:focus, .form-group select:focus {
            border-color: #007bff;
        }

        /* 增加输入框聚焦时的样式 */
        .detail-input:focus {
            box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
        }

        /* 增强按钮的悬停效果 */
        .btn-primary:hover {
            background-color: #0056b3;
        }

        .btn-danger:hover {
            background-color: #c82333;
        }

        .flash-message.error {
          color: white;
          background-color: red;
          padding: 10px;
          margin-bottom: 10px;
        }

        .flash-message.success {
          color: white;
          background-color: green;
          padding: 10px;
          margin-bottom: 10px;
        }
    </style>
</head>
<body>
<div class="title-container">
    <h2>产品详细信息</h2>
    {% with messages = get_flashed_messages(with_categories=true) %}
    {% if messages %}
    {% for category, message in messages %}
    {% if category == 'error' %}
    <div class="flash-message error">{{ message }}</div>
    {% else %}
    <div class="flash-message success">{{ message }}</div>
    {% endif %}
    {% endfor %}
    {% endif %}
    {% endwith %}
</div>
<div class="container">
    <form id="productForm" action="/upload_image_endpoint/{{ product_info[0] }}" method="POST"
          enctype="multipart/form-data">
        <div class="image-container">
            <img src="{{ url_for('static', filename=converted_path) }}" class="card-img-top product-img" alt="{{ product_info[3] }}" width="300"
                 height="300" onclick="openModal();currentSlide(1)">
        </div>
        <div style="text-align: center;">
            <label for="update-image" class="btn btn-primary"
                   style="display: inline-block; margin-top: 10px;">更新产品图片</label>
            <input id="update-image" name="update-image" type="file" style="display: none;"
                   onchange="this.form.submit()"
                   accept="image/*">
        </div>
    </form>
    <div class="details-container">
        <div>
            <form action="/product_save" method="POST" enctype="multipart/form-data">
                <div class="form-row">
                    <div class="form-group">
                        <span class="detail-title">产品&nbsp;&nbsp;&nbsp;ID：</span>
                        <input id="id" name="id" type="text" value="{{ product_info[0] }}" class="detail-input"
                               readonly/>
                    </div>
                    <div class="form-group">
                        <label for="customer_id">所属公司：</label>
                        <select id="customer_id" name="customer_id">
                            <option value="{{ customer_info[0] }}">{{ customer_info[1] }}</option>
                            {% for customer_list in customer_list %}
                            <option value="{{ customer_list[0] }}">{{ customer_list[1] }}</option>
                            {% endfor %}
                        </select>
                    </div>
                </div>
                <div class="form-row">
                    <div class="form-group">
                        <label for="class_id">产品类别：</label>
                        <select id="class_id" name="class_id">
                            <option value="{{ class_info[0] }}">{{ class_info[1] }}</option>
                            {% for class_list in class_list %}
                            <option value="{{ class_list[0] }}">{{ class_list[1] }}</option>
                            {% endfor %}
                        </select>
                    </div>
                    <div class="form-group">
                        <span class="detail-title">名&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;称：</span>
                        <input type="text" id="productName" name="productName" type="text" value="{{ product_info[3] }}"
                               class="detail-input"/>
                    </div>
                </div>
                <div class="form-row">
                    <div class="form-group">
                        <span class="detail-title">规格型号：</span>
                        <input id="productModel" name="productModel" type="text" value="{{ product_info[4] }}"
                               class="detail-input"/>
                    </div>
                    <div class="form-group">
                        <span class="detail-title">颜&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;色：</span>
                        <input id="productColor" name="productColor" type="text" value="{{ product_info[5] }}"
                               class="detail-input"/>
                    </div>
                </div>
                <div class="form-row">
                    <div class="form-group">
                        <span class="detail-title">计量单位：</span>
                        <input id="productUnit" name="productUnit" type="text" value="{{ product_info[6] }}"
                               class="detail-input"/>
                    </div>
                    <div class="form-group">
                        <span class="detail-title">采购价格：</span>
                        <input id="purchasePrice" name="purchasePrice" type="text" value="{{ product_info[7] }}"
                               class="detail-input"/>
                    </div>
                </div>
                <div class="form-row">
                    <div class="form-group">
                        <span class="detail-title">销售价格：</span>
                        <input id="salesPrice" name="salesPrice" type="text" value="{{ product_info[8] }}"
                               class="detail-input"/>
                    </div>
                </div>
                <button type="submit" class="btn btn-primary save-btn">保存</button>
            </form>
        </div>
        <div class="actions-column">
            <form action="/product_delete/{{ product_info[0] }}" method="post">
                <button type="submit" class="btn btn-danger delete-btn">删除</button>
            </form>
        </div>
    </div>
</div>

<div id="myModal" class="modal">
    <span class="close" onclick="closeModal()">&times;</span>
    <img class="modal-content" id="img01">
</div>


<script>
    function openModal() {
        document.getElementById('myModal').style.display = "block";
        document.getElementById('img01').src = document.querySelector('.product-img').src;
    }

    function closeModal() {
        document.getElementById('myModal').style.display = "none";
    }

</script>
</body>
</html>
